Load all required libraries.
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.1 ✓ dplyr 1.0.0
## ✓ tidyr 1.1.0 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke, cases_per_100000_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
#WRF C LOD values are coming up as NA, should be 0?
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
## Warning: Ignoring 1 observations
p2
## Warning: `group_by_()` is deprecated as of dplyr 0.7.0.
## Please use `group_by()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
Combine the two main plot pieces as a subplot
p_combined <-
plotly::subplot(p2,p1, # plots to combine, top to bottom
nrows = 2,
heights = c(.6,.4), # relative heights of the two plots
shareX = TRUE, # plots will share an X axis
titleY = TRUE
) %>%
# create a vertical "spike line" to compare data across 2 plots
plotly::layout(
xaxis = list(
spikethickness = 1,
spikedash = "dot",
spikecolor = "black",
spikemode = "across+marker",
spikesnap = "cursor"
),
yaxis = list(spikethickness = 0)
)
## Warning: Ignoring 1 observations
p_combined
Save the plot to pull into the index
#save(p_combined, file = "./plotly_fig.rda")
Save an htmlwidget for website embedding
#htmlwidgets::saveWidget(p_combined, "plotly_fig.html")
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#build a function here to make smooth frames so we don't repeat everything in huge loops
#FOR INDIVIDUAL FIGURES ONLY
make_n1_smooth_frame <- function(df){
smooth_n1 <- df %>% select(-c(Facility)) %>%
group_by(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke, cases_per_100000_clarke) %>%
summarize(sum_copy_num_L = sum(mean_total_copies)) %>%
ungroup() %>%
mutate(log_sum_copies_L = log10(sum_copy_num_L)) %>%
mutate(target = "N1")
return(smooth_n1)
}
make_n2_smooth_frame <- function(df){
smooth_n1 <- df %>% select(-c(Facility)) %>%
group_by(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke, cases_per_100000_clarke) %>%
summarize(sum_copy_num_L = sum(mean_total_copies)) %>%
ungroup() %>%
mutate(log_sum_copies_L = log10(sum_copy_num_L)) %>%
mutate(target = "N2")
return(smooth_n1)
}
#run frames through the functions
wrfa_smooth_n1 <- make_n1_smooth_frame(wrf_a_only_n1)
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
wrfb_smooth_n1 <- make_n1_smooth_frame(wrf_b_only_n1)
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
wrfc_smooth_n1 <- make_n1_smooth_frame(wrf_c_only_n1)
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
wrfa_smooth_n2 <- make_n2_smooth_frame(wrf_a_only_n2)
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
wrfb_smooth_n2 <- make_n2_smooth_frame(wrf_b_only_n2)
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
wrfc_smooth_n2 <- make_n2_smooth_frame(wrf_c_only_n2)
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
#get max date
maxdate <- max(wrfa_smooth_n1$date)
mindate <- min(wrfa_smooth_n1$date)
Build loess smoothing figures figures
#COMBINED FIGURE ONLY
#create smoothing data frames
#n1
smooth_n1 <- only_n1 %>% select(-c(Facility)) %>%
group_by(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke, cases_per_100000_clarke) %>%
summarize(sum_copy_num_L = sum(mean_total_copies)) %>%
ungroup() %>%
mutate(log_sum_copies_L = log10(sum_copy_num_L)) %>%
mutate(target = "N1")
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
#n2
smooth_n2 <- only_n2 %>% select(-c(Facility)) %>%
group_by(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke, cases_per_100000_clarke) %>%
summarize(sum_copy_num_L = sum(mean_total_copies)) %>%
ungroup() %>%
mutate(log_sum_copies_L = log10(sum_copy_num_L)) %>%
mutate(target = "N2")
## `summarise()` regrouping output by 'date', 'cases_cum_clarke', 'new_cases_clarke', 'X7_day_ave_clarke' (override with `.groups` argument)
#**************************************COMBINED PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#n1 extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_n1 <- ggplot(smooth_n1, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n1<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 134)
## Warning: Ignoring unknown aesthetics: outfit
#n2 extract
extract_n2 <- ggplot(smooth_n2, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n2<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 134)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#n1
extract_n1
## `geom_smooth()` using formula 'y ~ x'
fit_n1
## [1] 11.07337 11.23133 11.38495 11.53368 11.67693 11.81416 11.94480 12.06829
## [9] 12.18474 12.29492 12.39927 12.49822 12.59221 12.68168 12.76705 12.84669
## [17] 12.91899 12.98440 13.04338 13.09637 13.14384 13.18625 13.22404 13.25768
## [25] 13.28762 13.31432 13.33822 13.35980 13.37950 13.38823 13.37842 13.35280
## [33] 13.31410 13.26505 13.20838 13.14682 13.08310 13.01996 12.96012 12.90631
## [41] 12.86127 12.82772 12.80839 12.79060 12.76303 12.73048 12.69771 12.66954
## [49] 12.65073 12.64608 12.65363 12.66774 12.68770 12.71279 12.74229 12.77547
## [57] 12.81162 12.85002 12.88994 12.93066 12.97148 13.01166 13.05048 13.08723
## [65] 13.13082 13.18895 13.25910 13.33872 13.42528 13.51625 13.60909 13.70127
## [73] 13.79025 13.87351 13.94849 14.01268 14.06354 14.09853 14.12572 14.15365
## [81] 14.18047 14.20436 14.22346 14.23594 14.23997 14.23245 14.21265 14.18225
## [89] 14.14294 14.09640 14.04433 13.98841 13.93032 13.87175 13.81439 13.75992
## [97] 13.71004 13.66642 13.63075 13.59809 13.56277 13.52539 13.48654 13.44683
## [105] 13.40685 13.36719 13.32846 13.29124 13.25614 13.22376 13.19469 13.16952
## [113] 13.14886 13.12992 13.11009 13.09021 13.07111 13.05364 13.03864 13.02693
## [121] 13.01797 13.01062 13.00489 13.00080 12.99833 12.99750 12.99831 13.00077
## [129] 13.00488 13.01064 13.01807 13.02716 13.03791 13.05035
#n2
extract_n2
## `geom_smooth()` using formula 'y ~ x'
fit_n2
## [1] 10.85262 11.04904 11.24008 11.42528 11.60418 11.77632 11.94124 12.09848
## [9] 12.24811 12.39074 12.52675 12.65647 12.78028 12.89854 13.01160 13.11816
## [17] 13.21693 13.30828 13.39257 13.47016 13.54141 13.60669 13.66637 13.72079
## [25] 13.77034 13.81537 13.85625 13.89333 13.92699 13.94907 13.95282 13.94070
## [33] 13.91517 13.87869 13.83373 13.78275 13.72821 13.67257 13.61830 13.56786
## [41] 13.52370 13.48830 13.46411 13.43359 13.38313 13.32109 13.25586 13.19579
## [49] 13.14927 13.12467 13.11573 13.11046 13.10862 13.10998 13.11428 13.12130
## [57] 13.13078 13.14249 13.15619 13.17164 13.18859 13.20681 13.22605 13.24608
## [65] 13.27364 13.31417 13.36549 13.42538 13.49164 13.56207 13.63446 13.70661
## [73] 13.77633 13.84140 13.89962 13.94879 13.98672 14.01118 14.02748 14.04219
## [81] 14.05506 14.06584 14.07429 14.08016 14.08320 14.08030 14.06929 14.05126
## [89] 14.02731 13.99856 13.96611 13.93107 13.89454 13.85762 13.82143 13.78706
## [97] 13.75563 13.72824 13.70599 13.68558 13.66326 13.63942 13.61451 13.58892
## [105] 13.56309 13.53742 13.51234 13.48827 13.46562 13.44481 13.42626 13.41038
## [113] 13.39761 13.38617 13.37437 13.36269 13.35160 13.34159 13.33313 13.32670
## [121] 13.32198 13.31831 13.31569 13.31411 13.31357 13.31407 13.31560 13.31816
## [129] 13.32175 13.32637 13.33201 13.33867 13.34634 13.35503
#assign fits to a vector
n1_trend <- fit_n1
n2_trend <- fit_n2
#extract y min and max for each
limits_n1 <- ggplot_build(extract_n1)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n1 <- as.data.frame(limits_n1)
n1_ymin <- limits_n1$ymin
n1_ymax <- limits_n1$ymax
limits_n2 <- ggplot_build(extract_n2)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n2 <- as.data.frame(limits_n2)
n2_ymin <- limits_n2$ymin
n2_ymax <- limits_n2$ymax
#reassign dataframes (just to be safe)
work_n1 <- smooth_n1
work_n2 <- smooth_n2
#fill in missing dates to smooth fits
work_n1 <- work_n1 %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n1 <- work_n1$date
work_n2 <- work_n2 %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n2 <- work_n2$date
#create a new smooth dataframe to layer
smooth_frame_n1 <- data.frame(date_vec_n1, n1_trend, n1_ymin, n1_ymax)
smooth_frame_n2 <- data.frame(date_vec_n2, n2_trend, n2_ymin, n2_ymax)
#make plotlys
#**************************************COMBINED PLOT**********************************************
#plot smooth frames
p3 <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_n1, y = ~n1_trend,
data = smooth_frame_n1,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1,
'</br> Median Log Copies: ', round(n1_trend, digits = 2),
'</br> Target: N1'),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_lines(x = ~date_vec_n2, y = ~n2_trend,
data = smooth_frame_n2,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2,
'</br> Median Log Copies: ', round(n2_trend, digits = 2),
'</br> Target: N2'),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_ribbons(x ~date_vec_n1, ymin = ~n1_ymin, ymax = ~n1_ymax,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1, #leaving in case we want to change
'</br> Max Log Copies: ', round(n1_ymax, digits = 2),
'</br> Min Log Copies: ', round(n1_ymin, digits = 2),
'</br> Target: N1'),
name = "",
line = list(color = '#1B9E77')) %>%
plotly::add_ribbons(x ~date_vec_n2, ymin = ~n2_ymin, ymax = ~n2_ymax,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2, #leaving in case we want to change
'</br> Max Log Copies: ', round(n2_ymax, digits = 2),
'</br> Min Log Copies: ', round(n2_ymin, digits = 2),
'</br> Target: N2'),
name = "",
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
plotly::add_segments(x = as.Date("2020-06-24"),
xend = as.Date("2020-06-24"),
y = ~min(n1_ymin), yend = ~max(n1_ymax),
opacity = 0.35,
name = "Bars Repoen",
hoverinfo = "text",
text = "</br> Bars Reopen",
"</br> 2020-06-24",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-07-09"),
xend = as.Date("2020-07-09"),
y = ~min(n1_ymin), yend = ~max(n1_ymax),
opacity = 0.35,
name = "Mask Mandate",
hoverinfo = "text",
text = "</br> Mask Mandate",
"</br> 2020-07-09",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-08-20"),
xend = as.Date("2020-08-20"),
y = ~min(n1_ymin), yend = ~max(n1_ymax),
opacity = 0.35,
name = "</br> Classes Begin",
"</br> 2020-08-20",
hoverinfo = "text",
text = "Classes Begin",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = smooth_n1,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65)) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = smooth_n2,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p3
Create final trend plot by stacking with epidemic curve
smooth_extracttest <-
plotly::subplot(p3,p1, # plots to combine, top to bottom
nrows = 2,
heights = c(.6,.4), # relative heights of the two plots
shareX = TRUE, # plots will share an X axis
titleY = TRUE
) %>%
# create a vertical "spike line" to compare data across 2 plots
plotly::layout(
xaxis = list(
spikethickness = 1,
spikedash = "dot",
spikecolor = "black",
spikemode = "across+marker",
spikesnap = "cursor"
),
yaxis = list(spikethickness = 0)
)
## Warning: Ignoring 1 observations
smooth_extracttest
#save(smooth_extracttest, file = "./smooth_extracttest.rda")
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#n1 extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_n1a <- ggplot(wrfa_smooth_n1, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n1a<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 134)
## Warning: Ignoring unknown aesthetics: outfit
#n2 extract
extract_n2a <- ggplot(wrfa_smooth_n2, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n2a<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 134)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#n1
extract_n1a
## `geom_smooth()` using formula 'y ~ x'
fit_n1a
## [1] 11.16556 11.23387 11.30054 11.36511 11.42712 11.48611 11.54163 11.59320
## [9] 11.64093 11.68548 11.72721 11.76651 11.80375 11.83930 11.87354 11.90515
## [17] 11.93279 11.95682 11.97759 11.99546 12.01079 12.02394 12.03525 12.04509
## [25] 12.05381 12.06177 12.06932 12.07683 12.08464 12.08593 12.07502 12.05396
## [33] 12.02479 11.98957 11.95034 11.90918 11.86811 11.82920 11.79450 11.76606
## [41] 11.74593 11.73617 11.73882 11.74991 11.76410 11.78144 11.80196 11.82569
## [49] 11.85268 11.88296 11.91995 11.96622 12.02051 12.08155 12.14807 12.21882
## [57] 12.29252 12.36792 12.44375 12.51875 12.59166 12.66120 12.72613 12.78516
## [65] 12.84971 12.92997 13.02285 13.12524 13.23405 13.34620 13.45859 13.56812
## [73] 13.67171 13.76626 13.84867 13.91586 13.96472 13.99217 14.00660 14.01786
## [81] 14.02509 14.02740 14.02391 14.01374 13.99602 13.96092 13.90169 13.82207
## [89] 13.72579 13.61656 13.49812 13.37421 13.24854 13.12485 13.00686 12.89832
## [97] 12.80293 12.72444 12.66657 12.61960 12.57178 12.52385 12.47652 12.43053
## [105] 12.38659 12.34544 12.30779 12.27437 12.24590 12.22311 12.20673 12.19747
## [113] 12.19606 12.19841 12.20098 12.20531 12.21296 12.22548 12.24442 12.27134
## [121] 12.30516 12.34378 12.38719 12.43537 12.48832 12.54602 12.60847 12.67565
## [129] 12.74755 12.82417 12.90549 12.99150 13.08220 13.17757
#n2
extract_n2a
## `geom_smooth()` using formula 'y ~ x'
fit_n2a
## [1] 10.66845 10.86236 11.05097 11.23378 11.41032 11.58009 11.74261 11.89739
## [9] 12.04451 12.18461 12.31809 12.44532 12.56671 12.68264 12.79350 12.89801
## [17] 12.99485 13.08437 13.16694 13.24291 13.31263 13.37646 13.43476 13.48787
## [25] 13.53616 13.57998 13.61968 13.65562 13.68816 13.70917 13.71190 13.69882
## [33] 13.67237 13.63500 13.58916 13.53731 13.48189 13.42535 13.37015 13.31874
## [41] 13.27356 13.23706 13.21171 13.17967 13.12726 13.06309 12.99577 12.93392
## [49] 12.88615 12.86109 12.85301 12.85011 12.85189 12.85784 12.86748 12.88029
## [57] 12.89579 12.91347 12.93284 12.95339 12.97462 12.99605 13.01715 13.03745
## [65] 13.06627 13.11129 13.16957 13.23814 13.31405 13.39433 13.47603 13.55620
## [73] 13.63187 13.70008 13.75788 13.80232 13.83042 13.83924 13.83621 13.83046
## [81] 13.82159 13.80918 13.79281 13.77209 13.74658 13.70756 13.64866 13.57307
## [89] 13.48398 13.38457 13.27802 13.16753 13.05627 12.94743 12.84420 12.74976
## [97] 12.66729 12.59999 12.55103 12.51225 12.47373 12.43602 12.39967 12.36522
## [105] 12.33321 12.30420 12.27873 12.25736 12.24061 12.22905 12.22322 12.22366
## [113] 12.23092 12.24177 12.25343 12.26721 12.28437 12.30621 12.33401 12.36905
## [121] 12.41044 12.45642 12.50699 12.56213 12.62183 12.68608 12.75487 12.82818
## [129] 12.90601 12.98834 13.07516 13.16645 13.26222 13.36244
#assign fits to a vector
n1_trenda <- fit_n1a
n2_trenda <- fit_n2a
#extract y min and max for each
limits_n1a <- ggplot_build(extract_n1a)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n1a <- as.data.frame(limits_n1a)
n1_ymina <- limits_n1a$ymin
n1_ymaxa <- limits_n1a$ymax
limits_n2a <- ggplot_build(extract_n2a)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n2a <- as.data.frame(limits_n2a)
n2_ymina <- limits_n2a$ymin
n2_ymaxa <- limits_n2a$ymax
#reassign dataframes (just to be safe)
work_n1a <- wrfa_smooth_n1
work_n2a<- wrfa_smooth_n1
#fill in missing dates to smooth fits
work_n1a <- work_n1a %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n1a <- work_n1a$date
work_n2a <- work_n2a %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n2a <- work_n2a$date
#create a new smooth dataframe to layer
smooth_frame_n1a <- data.frame(date_vec_n1a, n1_trenda, n1_ymina, n1_ymaxa)
smooth_frame_n2a <- data.frame(date_vec_n2a, n2_trenda, n2_ymina, n2_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_n1a, y = ~n1_trenda,
data = smooth_frame_n1a,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1a,
'</br> Median Log Copies: ', round(n1_trenda, digits = 2),
'</br> Target: N1'),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_lines(x = ~date_vec_n2a, y = ~n2_trenda,
data = smooth_frame_n2a,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2a,
'</br> Median Log Copies: ', round(n2_trenda, digits = 2),
'</br> Target: N2'),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_ribbons(x ~date_vec_n1a, ymin = ~n1_ymina, ymax = ~n1_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1a, #leaving in case we want to change
'</br> Max Log Copies: ', round(n1_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(n1_ymina, digits = 2),
'</br> Target: N1'),
name = "",
line = list(color = '#1B9E77')) %>%
plotly::add_ribbons(x ~date_vec_n2a, ymin = ~n2_ymina, ymax = ~n2_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2a, #leaving in case we want to change
'</br> Max Log Copies: ', round(n2_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(n2_ymina, digits = 2),
'</br> Target: N2'),
name = "",
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_segments(x = as.Date("2020-06-24"),
xend = as.Date("2020-06-24"),
y = ~min(n1_ymina), yend = ~max(n1_ymaxa),
opacity = 0.35,
name = "Bars Repoen",
hoverinfo = "text",
text = "</br> Bars Reopen",
"</br> 2020-06-24",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-07-09"),
xend = as.Date("2020-07-09"),
y = ~min(n1_ymina), yend = ~max(n1_ymaxa),
opacity = 0.35,
name = "Mask Mandate",
hoverinfo = "text",
text = "</br> Mask Mandate",
"</br> 2020-07-09",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-08-20"),
xend = as.Date("2020-08-20"),
y = ~min(n1_ymina), yend = ~max(n1_ymaxa),
opacity = 0.35,
name = "</br> Classes Begin",
"</br> 2020-08-20",
hoverinfo = "text",
text = "Classes Begin",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-10-03"),
xend = as.Date("2020-10-03"),
y = ~min(n1_ymina), yend = ~max(n1_ymaxa),
opacity = 0.35,
name = "</br> First Home Football Game",
"</br> 2020-10-03",
hoverinfo = "text",
text = "First Home Football Game",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = wrfa_smooth_n1,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65)) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = wrfa_smooth_n2,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#n1 extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_n1b <- ggplot(wrfb_smooth_n1, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n1b<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 134)
## Warning: Ignoring unknown aesthetics: outfit
#n2 extract
extract_n2b <- ggplot(wrfb_smooth_n2, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n2b<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 134)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#n1
extract_n1b
## `geom_smooth()` using formula 'y ~ x'
fit_n1b
## [1] 10.69800 10.82908 10.95617 11.07878 11.19644 11.30866 11.41496 11.51485
## [9] 11.60843 11.69637 11.77903 11.85680 11.93005 11.99915 12.06449 12.12461
## [17] 12.17810 12.22534 12.26674 12.30270 12.33363 12.35993 12.38200 12.40024
## [25] 12.41505 12.42684 12.43601 12.44296 12.44809 12.44180 12.41620 12.37424
## [33] 12.31887 12.25305 12.17973 12.10185 12.02239 11.94427 11.87047 11.80394
## [41] 11.74761 11.70446 11.67743 11.65278 11.61824 11.57899 11.54020 11.50705
## [49] 11.48471 11.47836 11.48532 11.49903 11.51883 11.54405 11.57402 11.60808
## [57] 11.64556 11.68578 11.72810 11.77184 11.81633 11.86090 11.90490 11.94764
## [65] 11.99910 12.06776 12.15083 12.24547 12.34887 12.45822 12.57069 12.68347
## [73] 12.79374 12.89868 12.99547 13.08130 13.15334 13.20878 13.26168 13.32433
## [81] 13.39121 13.45680 13.51559 13.56207 13.59072 13.60198 13.60094 13.58905
## [89] 13.56774 13.53847 13.50268 13.46183 13.41734 13.37068 13.32329 13.27662
## [97] 13.23210 13.19120 13.15535 13.11948 13.07819 13.03246 12.98328 12.93161
## [105] 12.87844 12.82475 12.77152 12.71972 12.67033 12.62434 12.58272 12.54644
## [113] 12.51650 12.48909 12.46034 12.43108 12.40215 12.37437 12.34858 12.32562
## [121] 12.30494 12.28545 12.26719 12.25015 12.23438 12.21987 12.20667 12.19478
## [129] 12.18422 12.17502 12.16720 12.16077 12.15576 12.15218
#n2
extract_n2b
## `geom_smooth()` using formula 'y ~ x'
fit_n2b
## [1] 10.40591 10.56179 10.71299 10.85940 11.00089 11.13735 11.26866 11.39470
## [9] 11.51551 11.63125 11.74198 11.84776 11.94862 12.04464 12.13587 12.22152
## [17] 12.30097 12.37443 12.44216 12.50438 12.56133 12.61324 12.66036 12.70292
## [25] 12.74115 12.77530 12.80559 12.83226 12.85555 12.86888 12.86690 12.85171
## [33] 12.82542 12.79011 12.74789 12.70085 12.65109 12.60072 12.55182 12.50650
## [41] 12.46685 12.43498 12.41297 12.38248 12.32992 12.26457 12.19571 12.13261
## [49] 12.08454 12.06078 12.05076 12.03829 12.02427 12.00958 11.99513 11.98179
## [57] 11.97046 11.96202 11.95737 11.95739 11.96298 11.97502 11.99440 12.02202
## [65] 12.06739 12.13685 12.22651 12.33245 12.45078 12.57759 12.70899 12.84108
## [73] 12.96996 13.09172 13.20246 13.29829 13.37530 13.42959 13.48052 13.54510
## [81] 13.61595 13.68567 13.74688 13.79217 13.81417 13.81299 13.79508 13.76259
## [89] 13.71764 13.66239 13.59897 13.52951 13.45616 13.38105 13.30631 13.23410
## [97] 13.16654 13.10577 13.05393 13.00302 12.94467 12.88046 12.81197 12.74078
## [105] 12.66847 12.59663 12.52682 12.46064 12.39967 12.34548 12.29966 12.26378
## [113] 12.23944 12.22028 12.19997 12.18004 12.16203 12.14751 12.13801 12.13508
## [121] 12.13769 12.14381 12.15346 12.16664 12.18337 12.20367 12.22756 12.25506
## [129] 12.28617 12.32092 12.35933 12.40140 12.44716 12.49663
#assign fits to a vector
n1_trendb <- fit_n1b
n2_trendb <- fit_n2b
#extract y min and max for each
limits_n1b <- ggplot_build(extract_n1b)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n1b <- as.data.frame(limits_n1b)
n1_yminb <- limits_n1b$ymin
n1_ymaxb <- limits_n1b$ymax
limits_n2b <- ggplot_build(extract_n2b)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n2b <- as.data.frame(limits_n2b)
n2_yminb <- limits_n2b$ymin
n2_ymaxb <- limits_n2b$ymax
#reassign dataframes (just to be safe)
work_n1b <- wrfb_smooth_n1
work_n2b<- wrfb_smooth_n1
#fill in missing dates to smooth fits
work_n1b <- work_n1b %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n1b <- work_n1b$date
work_n2b <- work_n2b %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n2b <- work_n2b$date
#create a new smooth dataframe to layer
smooth_frame_n1b <- data.frame(date_vec_n1b, n1_trendb, n1_yminb, n1_ymaxb)
smooth_frame_n2b <- data.frame(date_vec_n2b, n2_trendb, n2_yminb, n2_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_n1b, y = ~n1_trendb,
data = smooth_frame_n1b,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1b,
'</br> Median Log Copies: ', round(n1_trendb, digits = 2),
'</br> Target: N1'),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_lines(x = ~date_vec_n2b, y = ~n2_trendb,
data = smooth_frame_n2b,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2b,
'</br> Median Log Copies: ', round(n2_trendb, digits = 2),
'</br> Target: N2'),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_ribbons(x ~date_vec_n1b, ymin = ~n1_yminb, ymax = ~n1_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1b, #leaving in case we want to change
'</br> Max Log Copies: ', round(n1_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(n1_yminb, digits = 2),
'</br> Target: N1'),
name = "",
line = list(color = '#1B9E77')) %>%
plotly::add_ribbons(x ~date_vec_n2b, ymin = ~n2_yminb, ymax = ~n2_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2b, #leaving in case we want to change
'</br> Max Log Copies: ', round(n2_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(n2_yminb, digits = 2),
'</br> Target: N2'),
name = "",
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_segments(x = as.Date("2020-06-24"),
xend = as.Date("2020-06-24"),
y = ~min(n1_yminb), yend = ~max(n1_ymaxb),
opacity = 0.35,
name = "Bars Repoen",
hoverinfo = "text",
text = "</br> Bars Reopen",
"</br> 2020-06-24",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-07-09"),
xend = as.Date("2020-07-09"),
y = ~min(n1_yminb), yend = ~max(n1_ymaxb),
opacity = 0.35,
name = "Mask Mandate",
hoverinfo = "text",
text = "</br> Mask Mandate",
"</br> 2020-07-09",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-08-20"),
xend = as.Date("2020-08-20"),
y = ~min(n1_yminb), yend = ~max(n1_ymaxb),
opacity = 0.35,
name = "</br> Classes Begin",
"</br> 2020-08-20",
hoverinfo = "text",
text = "Classes Begin",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-10-03"),
xend = as.Date("2020-10-03"),
y = ~min(n1_yminb), yend = ~max(n1_ymaxb),
opacity = 0.35,
name = "</br> First Home Football Game",
"</br> 2020-10-03",
hoverinfo = "text",
text = "First Home Football Game",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = wrfb_smooth_n1,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65)) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = wrfb_smooth_n2,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** Does not work until raw data fixed #add trendlines #extract data from geom_smooth #n1 extract # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_n1c <- ggplot(wrfc_smooth_n1, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n1c<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 120)
## Warning: Ignoring unknown aesthetics: outfit
#n2 extract
extract_n2c <- ggplot(wrfc_smooth_n2, aes(x = date, y = log_sum_copies_L)) +
stat_smooth(aes(outfit=fit_n2c<<-..y..), method = "loess", color = '#1B9E77',
span = 0.6, n = 120)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#n1
extract_n1c
## `geom_smooth()` using formula 'y ~ x'
fit_n1c
## [1] 11.04157 11.12340 11.20256 11.27881 11.35195 11.42176 11.48801 11.55049
## [9] 11.60895 11.66345 11.71425 11.76160 11.80577 11.84701 11.88558 11.92175
## [17] 11.95576 11.98788 12.01837 12.04749 12.07549 12.10263 12.12546 12.14094
## [25] 12.14995 12.15337 12.15209 12.14697 12.13890 12.12877 12.11746 12.10584
## [33] 12.09479 12.08520 12.07795 12.07391 12.07429 12.07923 12.08799 12.09988
## [41] 12.11416 12.13013 12.14706 12.16424 12.18095 12.19649 12.21012 12.22113
## [49] 12.22880 12.23243 12.23313 12.23258 12.23088 12.22810 12.22435 12.21971
## [57] 12.21428 12.20815 12.20141 12.19415 12.18646 12.17844 12.17018 12.16176
## [65] 12.15620 12.15567 12.15903 12.16516 12.17292 12.18118 12.18879 12.19463
## [73] 12.19755 12.19644 12.19014 12.17752 12.15745 12.12880 12.08873 12.03631
## [81] 11.97332 11.90153 11.82269 11.73858 11.65095 11.56158 11.47222 11.38464
## [89] 11.30062 11.22190 11.15026 11.08746 11.02799 10.96609 10.90314 10.84054
## [97] 10.77969 10.72196 10.66877 10.62149 10.58152 10.55025 10.52907 10.51938
## [105] 10.52257 10.54003 10.56848 10.60382 10.64614 10.69553 10.75210 10.81594
## [113] 10.88717 10.96588 11.05216 11.14613 11.24787 11.35750 11.47511 11.60080
#n2
extract_n2c
## `geom_smooth()` using formula 'y ~ x'
fit_n2c
## [1] 11.40023 11.46747 11.53193 11.59309 11.65045 11.70350 11.75174 11.79467
## [9] 11.83149 11.86216 11.88726 11.90740 11.92318 11.93519 11.94403 11.95029
## [17] 11.95459 11.95751 11.95965 11.96161 11.96399 11.96739 11.96356 11.94529
## [25] 11.91473 11.87401 11.82528 11.77068 11.71234 11.65243 11.59306 11.53640
## [33] 11.48457 11.43973 11.40401 11.37955 11.36961 11.37484 11.39352 11.42392
## [41] 11.46432 11.51299 11.56820 11.62823 11.69135 11.75583 11.81996 11.88199
## [49] 11.94021 11.99289 12.05446 12.13771 12.23843 12.35241 12.47546 12.60335
## [57] 12.73189 12.85687 12.97408 13.07931 13.16837 13.23703 13.28111 13.29637
## [65] 13.28137 13.23996 13.17595 13.09317 12.99542 12.88652 12.77027 12.65050
## [73] 12.53101 12.41562 12.30814 12.21238 12.13216 12.07128 12.01977 11.96549
## [81] 11.90904 11.85104 11.79208 11.73276 11.67369 11.61547 11.55871 11.50401
## [89] 11.45197 11.40319 11.35829 11.31785 11.28041 11.24442 11.21039 11.17883
## [97] 11.15024 11.12512 11.10399 11.08735 11.07570 11.06955 11.06941 11.07579
## [105] 11.08918 11.11009 11.13718 11.16875 11.20477 11.24523 11.29011 11.33938
## [113] 11.39302 11.45102 11.51336 11.58001 11.65095 11.72617 11.80564 11.88935
#assign fits to a vector
n1_trendc <- fit_n1c
n2_trendc <- fit_n2c
#extract y min and max for each
limits_n1c <- ggplot_build(extract_n1c)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n1c <- as.data.frame(limits_n1c)
n1_yminc <- limits_n1c$ymin
n1_ymaxc <- limits_n1c$ymax
limits_n2c <- ggplot_build(extract_n2c)$data
## `geom_smooth()` using formula 'y ~ x'
limits_n2c <- as.data.frame(limits_n2c)
n2_yminc <- limits_n2c$ymin
n2_ymaxc <- limits_n2c$ymax
#reassign dataframes (just to be safe)
work_n1c <- wrfc_smooth_n1
work_n2c <- wrfc_smooth_n1
#fill in missing dates to smooth fits
work_n1c <- work_n1c %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n1c <- work_n1c$date
work_n2c <- work_n2c %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_n2c <- work_n2c$date
#create a new smooth dataframe to layer
smooth_frame_n1c <- data.frame(date_vec_n1c, n1_trendc, n1_yminc, n1_ymaxc)
smooth_frame_n2c <- data.frame(date_vec_n2c, n2_trendc, n2_yminc, n2_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_n1c, y = ~n1_trendc,
data = smooth_frame_n1c,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1c,
'</br> Median Log Copies: ', round(n1_trendc, digits = 2),
'</br> Target: N1'),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_lines(x = ~date_vec_n2c, y = ~n2_trendc,
data = smooth_frame_n2c,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2c,
'</br> Median Log Copies: ', round(n2_trendc, digits = 2),
'</br> Target: N2'),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_ribbons(x ~date_vec_n1c, ymin = ~n1_yminc, ymax = ~n1_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n1c, #leaving in case we want to change
'</br> Max Log Copies: ', round(n1_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(n1_yminc, digits = 2),
'</br> Target: N1'),
name = "",
line = list(color = '#1B9E77')) %>%
plotly::add_ribbons(x ~date_vec_n2c, ymin = ~n2_yminc, ymax = ~n2_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_n2c, #leaving in case we want to change
'</br> Max Log Copies: ', round(n2_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(n2_yminc, digits = 2),
'</br> Target: N2'),
name = "",
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_segments(x = as.Date("2020-06-24"),
xend = as.Date("2020-06-24"),
y = ~min(n1_yminc), yend = ~max(n1_ymaxc),
opacity = 0.35,
name = "Bars Repoen",
hoverinfo = "text",
text = "</br> Bars Reopen",
"</br> 2020-06-24",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-07-09"),
xend = as.Date("2020-07-09"),
y = ~min(n1_yminc), yend = ~max(n1_ymaxc),
opacity = 0.35,
name = "Mask Mandate",
hoverinfo = "text",
text = "</br> Mask Mandate",
"</br> 2020-07-09",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-08-20"),
xend = as.Date("2020-08-20"),
y = ~min(n1_yminc), yend = ~max(n1_ymaxc),
opacity = 0.35,
name = "</br> Classes Begin",
"</br> 2020-08-20",
hoverinfo = "text",
text = "Classes Begin",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_segments(x = as.Date("2020-10-03"),
xend = as.Date("2020-10-03"),
y = ~min(n1_yminc), yend = ~max(n1_ymaxc),
opacity = 0.35,
name = "</br> First Home Football Game",
"</br> 2020-10-03",
hoverinfo = "text",
text = "First Home Football Game",
showlegend = FALSE,
line = list(color = "black", dash = "dash")) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = wrfc_smooth_n1,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65)) %>%
plotly::add_markers(x = ~date, y = ~log_sum_copies_L,
data = wrfc_smooth_n2,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_sum_copies_L, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(smooth_frame_n1a, file = "./plotly_objs/smooth_frame_n1a.rda")
save(smooth_frame_n2a, file = "./plotly_objs/smooth_frame_n2a.rda")
save(smooth_frame_n1b, file = "./plotly_objs/smooth_frame_n1b.rda")
save(smooth_frame_n2b, file = "./plotly_objs/smooth_frame_n2b.rda")
save(smooth_frame_n1c, file = "./plotly_objs/smooth_frame_n1c.rda")
save(smooth_frame_n2c, file = "./plotly_objs/smooth_frame_n2c.rda")
save(date_vec_n1a, file = "./plotly_objs/date_vec_n1a.rda")
save(date_vec_n2a, file = "./plotly_objs/date_vec_n2a.rda")
save(date_vec_n1b, file = "./plotly_objs/date_vec_n1b.rda")
save(date_vec_n2b, file = "./plotly_objs/date_vec_n2b.rda")
save(date_vec_n1c, file = "./plotly_objs/date_vec_n1c.rda")
save(date_vec_n2c, file = "./plotly_objs/date_vec_n2c.rda")
save(n1_ymina, file = "./plotly_objs/n1_ymina.rda")
save(n1_ymaxa, file = "./plotly_objs/n1_ymaxa.rda")
save(n2_ymina, file = "./plotly_objs/n2_ymina.rda")
save(n2_ymaxa, file = "./plotly_objs/n2_ymaxa.rda")
save(n1_yminb, file = "./plotly_objs/n1_yminb.rda")
save(n1_ymaxb, file = "./plotly_objs/n1_ymaxb.rda")
save(n2_yminb, file = "./plotly_objs/n2_yminb.rda")
save(n2_ymaxb, file = "./plotly_objs/n2_ymaxb.rda")
save(n1_yminc, file = "./plotly_objs/n1_yminc.rda")
save(n1_ymaxc, file = "./plotly_objs/n1_ymaxc.rda")
save(n2_yminc, file = "./plotly_objs/n2_yminc.rda")
save(n2_ymaxc, file = "./plotly_objs/n2_ymaxc.rda")